package com.intellect.syncproject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

import org.apache.commons.io.filefilter.IOFileFilter;

public class REDirFilter implements IOFileFilter {

	List<Pattern>dirRegs;
	List<Pattern>fileRegs;
	
	public REDirFilter(List<Pattern> dirRegs, List<Pattern>fileRegs) {
		this.dirRegs = dirRegs;
		this.fileRegs = fileRegs;
	}
	
	@Override
	public boolean accept(File file) {

		String fileName = file.getName();
		System.out.println(">> Found file: " + fileName);
		for( Pattern filePattern : fileRegs ) {
			Matcher m = filePattern.matcher(fileName);
			if( m.find() ) {
				System.out.println("<< Accepted");
				return true;
			}
		}
		System.out.println("<< Rejected");
		return false;
	}

	@Override
	public boolean accept(File dir, String name) {

		System.out.println(">> Found dir: " + name);
		for( Pattern dirPattern : dirRegs ) {
			Matcher m = dirPattern.matcher(name);
			if( m.find() ) {
				System.out.println("<< Accepted");
				return true;
			}
		}
		
		System.out.println("<< Rejected");
		return false;
	}
	
	public boolean checkFN(String fn) {
		for( Pattern filePattern : fileRegs ) {
			Matcher m = filePattern.matcher(fn);
			if( m.find() ) {
				return true;
			}
		}
		return false;
		
	}
	
	public static void main(String[] args) {
		
	}

}
